package cn.engage.basic.controller;

import cn.engage.basic.dto.MailCodeDto;
import cn.engage.basic.dto.MailRegisterDto;
import cn.engage.basic.dto.PhoneSmsCodeDto;
import cn.engage.basic.service.VerifyCodeService;
import cn.engage.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 前端注册生成图片验证码
 */
@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {
    @Autowired
    private VerifyCodeService verifyCodeService;
    // 获取图形验证码，调用VerifyCodeUtils工具类
    @GetMapping("/image/{key}")
    public AjaxResult getVerifyCode(@PathVariable("key") String uuidKey){
        String img = verifyCodeService.getVerifyCode(uuidKey);
        return AjaxResult.me().success(img);
    }

    /**
     * 获取短信验证码
     * 手机注册发送验证码
     */
    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody @Valid PhoneSmsCodeDto dto) {
        verifyCodeService.smsCode(dto);
        return AjaxResult.me().success();
    }
    /**
     * 邮箱注册发送验证码
     */
    @PostMapping("/mailCode")
    public AjaxResult MailCode(@RequestBody @Valid MailCodeDto dto) {
        verifyCodeService.getMail(dto);
        return AjaxResult.me().success();
    }



}
